package com.jiuyin.dianjing.ui.activity.setting;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.jiuyin.dianjing.R;
import com.jiuyin.dianjing.ui.activity.base.BaseActivity;
import com.jiuyin.dianjing.util.RegexTool;
import com.jiuyin.dianjing.util.ToastUtil;

import butterknife.BindView;
import butterknife.OnClick;

import static com.jiuyin.dianjing.api.constant.ApiConstant.KEY_MOBILE;

/**
 * 修改手机号码
 */
public class ModifyPhoneActivity extends BaseActivity {
    @BindView(R.id.edt_phone)
    EditText mNewPhone;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_modify_phone;
    }

    @Override
    protected void initData() {


    }

    @Override
    protected void initView() {
        setTitle(R.string.setting_phone_modify);
    }

    @OnClick({R.id.tv_done})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_done:
                sendNewPhoneNumber();
                break;
        }
    }

    /**
     * 传递新的手机号
     */
    private void sendNewPhoneNumber() {
        String newPhone = mNewPhone.getText().toString();
        if (TextUtils.isEmpty(newPhone)) {
            ToastUtil.showShort(R.string.setting_phone_modify_phone);
            return;
        }
        if (!RegexTool.instance().isMobile(newPhone)) {
            ToastUtil.showShort(R.string.login_normal_phone_tips);
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putString(KEY_MOBILE, newPhone);
        goTargetActivity(ModifyNewPhoneDoneActivity.class, bundle);
    }
}
